package com.moxiao.yfjh.module.order.dal.mysql.blindTradeRefund;

import cn.hutool.core.util.StrUtil;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.moxiao.yfjh.framework.common.pojo.PageResult;
import com.moxiao.yfjh.framework.mybatis.core.mapper.BaseMapperX;
import com.moxiao.yfjh.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.moxiao.yfjh.module.blind.dal.dataobject.member.BlindMemberUserDO;
import com.moxiao.yfjh.module.order.controller.admin.blindTradeRefund.vo.BlindTradeRefundExportReqVO;
import com.moxiao.yfjh.module.order.controller.admin.blindTradeRefund.vo.BlindTradeRefundPageReqVO;
import com.moxiao.yfjh.module.order.controller.admin.blindTradeRefund.vo.BlindTradeRefundRespVO;
import com.moxiao.yfjh.module.order.dal.dataobject.blindTradeRefund.BlindTradeRefundDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 相亲订单退款 Mapper
 *
 * @author mx
 */
@Mapper
public interface BlindTradeRefundMapper extends BaseMapperX<BlindTradeRefundDO> {

    default PageResult<BlindTradeRefundDO> selectPage(BlindTradeRefundPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BlindTradeRefundDO>()
                .eqIfPresent(BlindTradeRefundDO::getNo, reqVO.getNo())
                .eqIfPresent(BlindTradeRefundDO::getStatus, reqVO.getStatus())
                .eqIfPresent(BlindTradeRefundDO::getUserId, reqVO.getUserId())
                .eqIfPresent(BlindTradeRefundDO::getActiveNo, reqVO.getActiveNo())
                .likeIfPresent(BlindTradeRefundDO::getActiveName, reqVO.getActiveName())
                .eqIfPresent(BlindTradeRefundDO::getApplyReason, reqVO.getApplyReason())
                .eqIfPresent(BlindTradeRefundDO::getApplyDescription, reqVO.getApplyDescription())
                .eqIfPresent(BlindTradeRefundDO::getApplyPicUrls, reqVO.getApplyPicUrls())
                .eqIfPresent(BlindTradeRefundDO::getOrderId, reqVO.getOrderId())
                .eqIfPresent(BlindTradeRefundDO::getOrderNo, reqVO.getOrderNo())
                .betweenIfPresent(BlindTradeRefundDO::getAuditTime, reqVO.getAuditTime())
                .eqIfPresent(BlindTradeRefundDO::getAuditUserId, reqVO.getAuditUserId())
                .eqIfPresent(BlindTradeRefundDO::getAuditReason, reqVO.getAuditReason())
                .eqIfPresent(BlindTradeRefundDO::getRefundPrice, reqVO.getRefundPrice())
                .eqIfPresent(BlindTradeRefundDO::getPayRefundId, reqVO.getPayRefundId())
                .betweenIfPresent(BlindTradeRefundDO::getRefundTime, reqVO.getRefundTime())
                .betweenIfPresent(BlindTradeRefundDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BlindTradeRefundDO::getType, reqVO.getType())
                .orderByDesc(BlindTradeRefundDO::getId));
    }

    default List<BlindTradeRefundDO> selectList(BlindTradeRefundExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<BlindTradeRefundDO>()
                .eqIfPresent(BlindTradeRefundDO::getNo, reqVO.getNo())
                .eqIfPresent(BlindTradeRefundDO::getStatus, reqVO.getStatus())
                .eqIfPresent(BlindTradeRefundDO::getUserId, reqVO.getUserId())
                .eqIfPresent(BlindTradeRefundDO::getActiveNo, reqVO.getActiveNo())
                .likeIfPresent(BlindTradeRefundDO::getActiveName, reqVO.getActiveName())
                .eqIfPresent(BlindTradeRefundDO::getApplyReason, reqVO.getApplyReason())
                .eqIfPresent(BlindTradeRefundDO::getApplyDescription, reqVO.getApplyDescription())
                .eqIfPresent(BlindTradeRefundDO::getApplyPicUrls, reqVO.getApplyPicUrls())
                .eqIfPresent(BlindTradeRefundDO::getOrderId, reqVO.getOrderId())
                .eqIfPresent(BlindTradeRefundDO::getOrderNo, reqVO.getOrderNo())
                .betweenIfPresent(BlindTradeRefundDO::getAuditTime, reqVO.getAuditTime())
                .eqIfPresent(BlindTradeRefundDO::getAuditUserId, reqVO.getAuditUserId())
                .eqIfPresent(BlindTradeRefundDO::getAuditReason, reqVO.getAuditReason())
                .eqIfPresent(BlindTradeRefundDO::getRefundPrice, reqVO.getRefundPrice())
                .eqIfPresent(BlindTradeRefundDO::getPayRefundId, reqVO.getPayRefundId())
                .betweenIfPresent(BlindTradeRefundDO::getRefundTime, reqVO.getRefundTime())
                .betweenIfPresent(BlindTradeRefundDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BlindTradeRefundDO::getType, reqVO.getType())
                .orderByDesc(BlindTradeRefundDO::getId));
    }

    default PageResult<BlindTradeRefundRespVO> selectJoinPage(BlindTradeRefundPageReqVO reqVO) {
        return selectJoinPage(reqVO, BlindTradeRefundRespVO.class, new MPJLambdaWrapper<BlindTradeRefundDO>()
                .selectAll(BlindTradeRefundDO.class)
                .leftJoin(BlindMemberUserDO.class, BlindMemberUserDO::getId, BlindTradeRefundDO::getUserId)
                .selectAs(BlindMemberUserDO::getNickname, BlindTradeRefundRespVO::getNickname)
                .like(StrUtil.isNotBlank(reqVO.getNickname()), BlindMemberUserDO::getNickname, reqVO.getNickname())
                .eq(reqVO.getStatus() != null, BlindTradeRefundDO::getStatus, reqVO.getStatus())
                .eq(reqVO.getUserId() != null, BlindTradeRefundDO::getUserId, reqVO.getUserId())
                .orderByDesc(BlindTradeRefundDO::getCreateTime));
    }

    @Select("select count(*) from blind_trade_refund where no = #{no}")
    Integer getNo(@Param("no") String no);
}
